import httpclient from 'httpclient';
import api from '../../../api/api_kind.js';
export default {
    data() {
        return {
            home: {
                data: {}
            }
        };
    },
    mounted: function () {
        let routeFuncs = this.$store.state.routeFuncsList;
        if (routeFuncs === undefined) {
            httpclient.sendPost(api.LOGIN.MENU_LIST_BY_USER_ID).done((res) => {
                if (res.code === 1) {
                    this.home.data = res.data;
                    this.$store.commit("setRouteFuncs", this.home.data);
                } else {
                    ELEMENT.Message.warning({message: res.errorMsg});
                }
            }).fail((data) => {
                ELEMENT.Message.error({message: data.description});
            });
        } else {
            this.home.data = this.$store.state.routeFuncsList;
        }
    },
    methods: {
        /**
         *  点击系统功能切换路由
         * @param data 当前系统信息
         */
        onHome(data) {
            this.$store.commit("setRouteData", data);//同时变更当前系统路由
            this.$router.push({path: data.code,query:{_k:randomString(7)}});
        },
        loginOut() {//注销登录
            this.$confirm('此操作将退出登录, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                removeAllSessionStorage();
                removeAllLocalStorage();
                this.$router.push("/login");
            }).catch(() => {
                return false;
            });
        },
    }
};
